<template>
	<view>
		<view class="cart-container" v-if="cart.length">
			<my-address />
			<!-- 购物车标题区域 -->
			<view class="cart-title">
				<uni-icons type="shop" size="18"></uni-icons>
				<text class="cart-title-text">购物车</text>
			</view>
			<!-- 购物车列表区域 -->
			<uni-swipe-action>
				<block v-for="(item,index) in cart" :key="index">
					<uni-swipe-action-item  show="none" :right-options="options" @click="clickHandler(item)">
						<my-goods :goods="item" :showRadio="true" :showNumberBox="true" @radioChange="radioChangeHandler" @numberChange="numberChangeHandler" /> 
					</uni-swipe-action-item>
				</block>
			</uni-swipe-action>
			<my-settle />
		</view>
		<!-- 当购物车为空时渲染的盒子 -->
		<view class="empty-box" v-else>
			<image src="@/static/cart_empty@2x.png" class="empty-img"></image>
			<text class="tip-text">~空空如也~</text>
		</view>
	</view>
</template>

<script>
	import badgeMixin from "@/mixins/cart-badge.js"
	import {mapState,mapMutations} from "vuex"
	export default {
		data() {
			return {
				options: [{
					text: "删除",
					style: {
						backgroundColor: "#C00000",
					}
				}]
			};
		},
		mixins: [badgeMixin],
		computed: {
			...mapState("cartAbout",["cart"]),
		},
		methods: {
			...mapMutations("cartAbout",["updateGoodsState","updateGoodsCount","deleteGoodsById"]),
			radioChangeHandler(data) {
				this.updateGoodsState(data);
			},
			numberChangeHandler(data) {
				this.updateGoodsCount(data);
			},
			clickHandler(item) {
				this.deleteGoodsById(item);
			}
		},		
	}
</script>

<style lang="scss">
	.cart-container {
		padding-bottom: 50px;
		.cart-title {
			height: 40px;
			align-items: center;
			margin-left: 5px;
			border-bottom: 1px solid #efefef;
			.cart-title-text {
				font-size: 14px;
				margin-left: 10px;
			}
		}
	}
	.empty-box {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 150px;
		
		.empty-img {
			width: 90px;
			height: 90px;
		}
		.tip-text {
			font-size: 12px;
			color: gray;
			margin-top: 15px;
		}
	}	
</style>
